-
Notifications
You must be signed in to change notification settings - Fork 409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A test that triggers null pointer exception on 3rd level of external query #212
A test that triggers null pointer exception on 3rd level of external query #212
Conversation
Fixed by #213 |
I will review this. I think it would be helpful to add this (or a modified version) to wasmd to ensure we have no regressions. As the fix had no test with it. Essentially don't delete the branch, I will bring it into master with possibly a different contract |
Okay, for sure. #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum QueryMsg {
SendExternalQueryInfiniteLoop { to: HumanAddr, counter: u64 },
}
pub fn query<S: Storage, A: Api, Q: Querier>(deps: &Extern<S, A, Q>, msg: QueryMsg) -> QueryResult {
match msg {
QueryMsg::SendExternalQueryInfiniteLoop { to, counter } => {
send_external_query_infinite_loop(deps, to, counter)
}
}
}
fn send_external_query_infinite_loop<S: Storage, A: Api, Q: Querier>(
deps: &Extern<S, A, Q>,
contract_addr: HumanAddr,
counter: u64,
) -> QueryResult {
if counter >= 10 {
return Ok(Binary(counter.into()))
}
let answer = deps
.querier
.query::<u64>(&QueryRequest::Wasm(WasmQuery::Smart {
contract_addr: contract_addr.clone(),
msg: Binary(
format!(
r#"{{"send_external_query_infinite_loop":{{"to":"{}","counter":{}}}}}"#,
contract_addr.clone().to_string(),
counter + 1,
)
.into(),
),
}));
match answer {
Ok(counter) => Ok(Binary(counter.into())),
Err(e) => Err(e),
}
} |
And in go code: counter, err = keeper.QuerySmart(ctx, contractAddress, []byte(fmt.Sprintf(`{"send_external_query_infinite_loop":{"to":"%s","counter":1}}`, contractAddress.String())))
require.Equal(t, 10, counter) (Probably need to convert counter from bytes to uint64) |
Thanks, I will add such to the hackatom contract |
1 similar comment
Thanks, I will add such to the hackatom contract |
Use new --keyring-backend flag. See cosmos/cosmos-sdk#5355 for more information.
Also need to add a print in this line: https://github.com/CosmWasm/go-cosmwasm/blob/master/api/callbacks.go#L415
And then you'd see that
gasAfter == gasBefore
and that in the 3rd level of query that the vTable at the end ofquerier
is{<nil> <nil> <nil> <nil>}
, which leads to null pointer exception later on inkeeper.go/QuerySmart
.